
$(function(){
	function GetQueryString (name) { //获取指定name的url参数
        var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)");
        var r = window.location.search.substr(1).match(reg);
        if (r != null) return (r[2]);
        return null;
    }
    function Toast (txt){
        var toastHtml = '<div class="tk_info" id="tkInfo"></div>';
        var toast = $('body #tkInfo');
        if (toast.length) {
            toast.html(txt).show();
        }else{
            $('body').append(toastHtml);
            $('body #tkInfo').html(txt).show();
        }
        setTimeout(function(){
          $('body #tkInfo').hide();
        },2000)
    }

    const userId = GetQueryString('userId');
    const token = GetQueryString('token');
    const host = 'http://'+ GetQueryString('invokeDomain');

	$('.getRedBtb').on('click',function(){
		const val = $('.inp').val();
		if (!val) {
			Toast('邀请码不能为空！')
			return false
		};
		$.ajax({
            type:'get',
            dataType: 'json',
            url:host+'/system/api/appuser/modifyInfo',
            data: {
                'userId':userId,
                'token':token,
                'inviteCode':val
            },
            //请求成功时执行
            success: function(v) {
                const code = v.code;
                const msg = v.msg;
                const data = v.data;
                if (code == 0) {
                    $('.div1').html('已领取奖励');
                    $('.invitecode').hide();
                }else{
                    Toast(msg);
                }
            },
            //请求失败遇到异常触发
            error: function(d) {
                Toast(d.msg);
            }
        })
	})

	//返回app
    $('.back').on('click',function(){
        // window.history.back();
         H5brigeAPP.NativeBack()
    })
	
})